﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Data;
using BabyFood.Entities;

public partial class Controls_ControlMebauchiase : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThiTintuc_Mebauchiase();
        }
    }
    public void HienThiTintuc_Mebauchiase()
    {
        int totalRows = 0;
        string whereClause = "";

        // Thuc hien lay ID cua DM_LoaiTinTuc: Mon ngon theo tuoi
        TList<DmLoaiTinTuc> tlistLoaitintuc =
            DataRepository.DmLoaiTinTucProvider.GetPaged("Ten like N'%" + Common.Chuyenbabau + "%' and TrangThai = 1", "Id DESC", 0, 1,
                                                         out totalRows);

        int idLoaitintuc = 0;
        int idsubloaitintuc = 0;
        if (tlistLoaitintuc.Count > 0)
        {
            idLoaitintuc = tlistLoaitintuc[0].Id;
        }

        // Thuc hien lay ID sub loai tin tuc: Bep cua me
        TList<DmSubTinTuc> tlistSubtintuc = DataRepository.DmSubTinTucProvider.GetPaged("TenSubTinTuc like N'%" + Common.Mebauchiase + "%' and TrangThai = 1", "Id DESC", 0, 1,
                                                         out totalRows);
        if (tlistSubtintuc.Count > 0)
        {
            idsubloaitintuc = tlistSubtintuc[0].Id;
        }

        // Thuc hien lay danh sach cac tin tuc thuoc Bep cua me
        TList<TinTuc> tlistTintuc =
            DataRepository.TinTucProvider.GetPaged(
                "IdSubTinTuc = " + idsubloaitintuc,
                "NgayCapNhat DESC", 0, 8, out totalRows);

        if (tlistTintuc.Count > 0)
        {
            // Bindding du lieu de hien thi
            dlBepcuame.DataSource = tlistTintuc;
            dlBepcuame.DataBind();
        }
        else
        {
            litDataNotUpdate.Text = "Dữ liệu chưa được cập nhật";
        }

    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
}